﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.Revit;
using HYRevitCode.CurveUtility;
using HYRevitCode.XYZUtility;

namespace YJKRGeometry
{
	public class DataSerializeDeserialize
	{
		public static bool PointToString(XYZ point, out string pointString)
		{
			return XYZUtilityMethod.PointToString(point, out pointString);
		}

		public static bool StringToPoint(string pointString, out XYZ point)
		{
			return XYZUtilityMethod.StringToPoint(pointString, out point);
		}

		public static bool LineToString(Line line, out string lineString)
		{
			return CurveUtilityMethod.LineToString(line, out lineString);
		}

		public static bool StringToLine(Autodesk.Revit.DB.Document doc, string lineString, out Line line, bool isBound = true)
		{
			bool result;
			try
			{
				lineString = lineString.Substring(0, lineString.Length - 2);
				string[] array = lineString.Split(new char[]
				{
					':'
				});
				if (array[0] == "Line")
				{
					XYZ point = null;
					XYZ endOrDirection = null;
					DataSerializeDeserialize.StringToPoint(array[1], out point);
					DataSerializeDeserialize.StringToPoint(array[2], out endOrDirection);
					if (isBound)
					{
						line = doc.CreatYJKLine(point, endOrDirection, true);
					}
					else
					{
						line = doc.CreatYJKLine(point, endOrDirection, false);
					}
					result = true;
				}
				else
				{
					line = null;
					result = false;
				}
			}
			catch
			{
				line = null;
				result = false;
			}
			return result;
		}

		public static bool LineToString(List<Line> lstLine, out List<string> lstLineString)
		{
			return CurveUtilityMethod.LineToString(lstLine, out lstLineString);
		}
	}
}
